package com.movie.demo.controller;

import com.movie.demo.pojo.Discuss;
import com.movie.demo.Utlis.result.CommonResult;
import com.movie.demo.pojo.vo.DiscussInfo;
import com.movie.demo.service.impl.DiscussService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@CrossOrigin
public class DiscussController {
    @Autowired
    private DiscussService discussService;

    @RequestMapping("/AllDiscuss")
    public CommonResult<List> DiscussList(){
        List<DiscussInfo> discussesInfos= discussService.AllSelect();
        if(discussesInfos!=null){
            return CommonResult.success(discussesInfos);
        }
        return CommonResult.failed();
    }
    @RequestMapping("/Discuss")
    public CommonResult<List> DiscussSelect(@RequestBody Discuss discuss){
        List<DiscussInfo> discussesInfos= discussService.Selectdiscuss(discuss.getMid());
        if(discussesInfos!=null){
            return CommonResult.success(discussesInfos);
        }
        return CommonResult.failed();
    }
    @RequestMapping("/addDiscuss")
    public CommonResult addDiscussSelect(@RequestBody Discuss discuss){
        boolean result =discussService.addDiscuss(discuss);
        if (result){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
    @RequestMapping("/deleteDiscuss")
    public CommonResult deleteDiscuss(@RequestBody Discuss discuss){
        boolean result =discussService.deleteDiscuss(discuss.getDid());
        if (result){
            return CommonResult.success(result);
        }
        return CommonResult.failed();
    }
}
